﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using Webbshop.ServiceReference1;

namespace Webbshop
{
    public partial class ProductDetail : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ShoppeServiceClient proxy = new ShoppeServiceClient();
                try
                {
                    productDetail.DataSource = proxy.getTargetProduct(int.Parse(Request.QueryString["productID"]));
                    productDetail.DataBind();

                }
                finally
                {
                    proxy.Close();
                } 
            }

        }

        /// <summary>
        /// Event som sker när man trycker en kanpp i produktvyn.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        protected void Item_Command(object source, DataListCommandEventArgs e)
        {
            Session["ShoppingCart"] = Functions.GetCart(Session["ShoppingCart"] as Cart); // Hämta/Skapa Varukorg
            // Lägg till vara i varukorg
            Functions.AddToCart(Session["ShoppingCart"] as Cart, e.CommandArgument.ToString(), e.Item.ItemIndex);
            // Genomför Postback
            Response.Redirect(Request.Url.AbsolutePath + Request.Url.Query);
        }
        
    }
}